
<%@ page contentType="text/html;charset=UTF-8" language="java"  pageEncoding="UTF-8"%>

<style>
    .datagrid-header-row {
        background-color: #4dded8;
    }
    a:link {color: #6d73ff; text-decoration:none;}/* 未访问：蓝色、无下划线*/

    a:hover {color: red; text-decoration:underline;} /*鼠标移近：红色、下划线*/

</style>

<div class="order-table">
    <label for="state">状态:</label>
    <select id="state"  name="state" style="width: 100px;">
        <option value="">请选择</option>
        <option value="0">未审核</option>
        <option value="1000">审核通过</option>
    </select>
    <label for="customer">客户:</label>
    <input id="customer" type="text" name="customer"   />
    <label for="refs">单号:</label>
    <input type="text" id="refs" name="refs">
    <label>交货日期</label>
    <input class="easyui-datebox"  id="startDate" name="startDate" />-<input class="easyui-datebox"  id="endDate" name="endDate" />
    <em><a id="searchOrder" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-search'">查询</a></em>
    <i><a id="addOrder" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-add'">添加</a></i>
    <b><a id="reloadOrder" href="#" class="easyui-linkbutton"data-options="iconCls:'icon-reload'">刷新</a></b>
    <table id="soBillGrid"></table>
    <div id="addSoBillDialog"></div>
    <div id="soBillDetailDialog"></div>
    <input type="hidden" id="sbId" name="sbId">
</div>
<script>
    (function () {
        var table = $('#soBillGrid');
        table.datagrid({
            height: ($(window).height()*0.9),
            url:'api/bill/so/list',
            method: 'post',
            striped: true,
            fitColumns: true,
            singleSelect: true,
            pagination: true,  //true代表显示分页控件 ，而且传到后台的参数中会自动添加 page 和 row 两参数，后台直接就可以接收到
            pageSize: 15,//每页显示的记录条数，默认为15
            pageList: [15,25,35,50,70],//可以设置每页记录条数的列表
            columns: [[
                { field: 'act', title: '操作',  align: 'center',
                    formatter:function(value,rowData,index) {
                        return '<a href="javascript:;" check-out id="' + rowData.id + '" status="' + (rowData.billStatus ? 0 : 1000) +  '">' + (rowData.billStatus ? "取消审核" : "审核通过") + '</a>';
                    }
                },
                { field: 'ref', title: '销售单号',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.ref != null) {
                            return '<a findBySoBillId id="' + rowData.id + '" href="javascript:;" >'+rowData.ref+'</a>';
                        }
                    }
                },
                { field: 'dealDate', title: '交货日期', align: 'center' },
                { field: 'dealAddress', title: '交货地址',  align: 'center' },
                { field: 'billStatus', title: '单据状态',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.billStatus == "0") {
                            return "未审核";
                        }else if(rowData.billStatus == "1000"){
                            return "审核通过";
                        }
                    }
                },
                { field: 'customerId', title: '客户',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.customerId != null) {
                            return rowData.customerName;
                        }
                    }
                },
                { field: 'contact', title: '客户联系人',  align: 'center' },
                { field: 'tel', title: '客户电话', align: 'center' },
//                { field: 'fax', title: '传真', width: 50, align: 'center' },
                { field: 'goodsMoney', title: '销售金额',  align: 'center' },
                { field: 'tax', title: '税金',  align: 'center' },
                { field: 'moneyWithTax', title: '价税合计', align: 'center' },
                { field: 'receivingType', title: '收款方式',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.receivingType != null && rowData.receivingType=="1" ) {
                            return "现金收款";
                        }
                    }
                },
                { field: 'bizUserId', title: '业务员',  align: 'center',
                    formatter:function(value,rowData,index) {
                        if (rowData.bizUserId != null) {
                            return rowData.bizUserName;
                        }
                    }
                },
                { field: 'inputUserId', title: '制单人',  align: 'center' ,
                    formatter:function(value,rowData,index){
                    if(rowData.inputUserId != null){
                        return rowData.inputUserName;
                    }
                }},
                { field: 'dateCreated', title: '制单时间',  align: 'center' },
                { field: 'confirmUserId', title: '审核人',  align: 'center' ,
                    formatter:function(value,rowData,index){
                    if(rowData.confirmUserId != null){
                        return rowData.confirmUserName;
                    }
                }},
                { field: 'confirmDate', title: '审核时间', align: 'center' },
                { field: 'billMemo', title: '备注',width:50, align: 'center' }
            ]],
            loadFilter: function (data) {
                if(data != null ){
                    return data.data;
                }
            }
        });
        $('.order-table').on('click', 'a[check-out]', function (e) {
            e.preventDefault();
            var $this = $(this);
            console.log($this.attr('status'));
            e.stopPropagation();
            $.ajax({
                type: 'post',
                url: 'api/bill/so',
                data: {id: $this.attr('id'), billStatus: $this.attr('status')},
                success: function (data, status) {
                    if (data) {
                        $.messager.show({
                            title: '提示消息',
                            msg: data.message,
                            showType: 'show',
                            timeout: 2000,
                            style: {
                                right: '',
                                bottom: '',
                            }
                        });
                        table.datagrid('reload');
                    } else {
                        $.messager.alert('提示信息',data.message, 'warning');
                    }
                }
            });
        }).on('click','b',function (e) {
            e.preventDefault();
            e.stopPropagation();
            $('#state').val('');
            $('#customer').val('');
            $('#refs').val('');
            $('#startDate').datebox('setValue','');
            $('#endDate').datebox('setValue','');
            table.datagrid({
                url:'api/bill/so/list',
                queryParams:{page:"1",rows:"10"}
            });
        }).on('click', 'em', function (e) {
            e.preventDefault();
            var state=$('#state option:selected ').val();
            var customer= $('#customer').val();
            var refs=$('#refs').val();
            var startDate=$('#startDate').val();
            var endDate=$('#endDate').val();
            e.stopPropagation();
            table.datagrid({
                url:'api/bill/so/list',
                method: 'post',
                queryParams:{billStatus:state,customerName:customer,ref:refs,dealDate:startDate,bizDt:endDate,page:"1",rows:"10"}
            });
        }).on('click','i',function (e) {
            e.preventDefault();
            e.stopPropagation();
            $('#addSoBillDialog').dialog({
                title: '添加订单',
                width: 700,
                height: 300,
                closed: false,
                cache: false,
                href: 'page/order-add',
                modal: true
            });
        }).on('click','a[findBySoBillId]',function (e) {
            e.preventDefault();
            e.stopPropagation();
            $('#sbId').val($(this).attr('id'));
            $('#soBillDetailDialog').dialog({
                title: '订单详情',
                width: 1200,
                height: 500,
                closed: false,
                cache: false,
                href: 'page/sobill-detail',
                modal: true
            });
        });
    })();
</script>